package com.bjqg.bjqg01.bjqg.activity.longrange.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.JcxmBean;

import java.util.List;

/**
 * Created by bjqg01 on 2018/9/4.
 */

public class JcDialog extends Dialog {

    public JcDialog(@NonNull Context context) {
        super(context);
    }

    public JcDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
    }

    public static class Builde {
        private Context mContext;
        private OnClickListener closeListener;
        private OnClickListener click;


        public Builde setCloseListener(OnClickListener closeListener) {
            this.closeListener = closeListener;
            return this;
        }

        public Builde setConfireListener(OnClickListener click) {
            this.click = click;
            return this;
        }

        public Builde(Context mContext) {
            this.mContext = mContext;

        }

        public JcDialog create() {
            final LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            //加载布局
            final JcDialog dialog = new JcDialog(mContext, R.style.mystyle);
            View view = mInflater.inflate(R.layout.dialog_jc, null);
            dialog.addContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            if (closeListener != null) {
                ((TextView) view.findViewById(R.id.cancel_btn)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {//确定
                        closeListener.onClick(dialog,
                                DialogInterface.BUTTON_POSITIVE);
                    }
                });
            }

            if (click != null) {
                ((TextView) view.findViewById(R.id.confirm_btn)).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {//取消
                        click.onClick(dialog,
                                DialogInterface.BUTTON_POSITIVE);
                    }
                });
            }

            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(view);
            return dialog;
        }
    }
}
